//
// File:    mainwindow.cpp
// Brief:   主界面实现文件
//
// History:
// ============================================================================
// 2011-01-20    Finux Chen <finuxchen@gmail.com>    创建
//
//
#include <QtGui>
#include "mainwindow.h"
#include "progform.h"
#include "loadprogdlg.h"
#include "../core/ctrl.h"
#include "../core/ctrlthread.h"
#include "../core/measprog.h"
#include "measureform.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent)
{
	ui.setupUi(this);
	loadButton    = ui.loadButton;
	fileButton    = ui.fileButton;
	programButton = ui.programButton;
	measureButton = ui.measureButton;

	// set font size
	QFont font = this->font();
	font.setPixelSize(font.pointSize() * 4 / 3);
	setFont(font);

	setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
	showMaximized();

	connect(loadButton, SIGNAL(clicked()), this, SLOT(switchForms()));
	connect(fileButton, SIGNAL(clicked()), this, SLOT(switchForms()));
	connect(programButton, SIGNAL(clicked()), this, SLOT(switchForms()));
	connect(measureButton, SIGNAL(clicked()), this, SLOT(switchForms()));
}

MainWindow::~MainWindow()
{
	delete loadButton;
	delete fileButton;
	delete programButton;
	delete measureButton;
}

//
// 对工具栏按钮的相应函数
//
void MainWindow::switchForms()
{
	QPushButton *button = qobject_cast<QPushButton *>(sender());

//	Ctrl *ctrl = Ctrl::getInstance();
//	CtrlThread *thread = ctrl->getCtrlThread();
	MeasProg *meas_prog = MeasProg::getInstance();

	if(button == loadButton){
		LoadProgDlg *dlg = new LoadProgDlg();
		if(dlg->exec() == QDialog::Accepted){
			meas_prog->readProgFromFile(dlg->getFilePath());
		}
		delete dlg;
	}else if(button == fileButton){

	}else if(button == programButton){
		prog_form = new ProgForm;
		prog_form->show();
	}else if(button == measureButton){
		measure_form = new MeasureForm;
		measure_form->show();
	}
/*
    QAction *action = qobject_cast<QAction *>(sender());

	Ctrl* pCtrl = Ctrl::getInstance();
	CtrlThread* thread = pCtrl->getCtrlThread();

    if(action == actLoad){
		LoadProgDlg *dlg = new LoadProgDlg(this);
		if(QDialog::Accepted == dlg->exec()){
			QString path = dlg->getFilePath();
			frmProg->loadItems(path);
			progFilePathChanged(path);
		}
		delete dlg;
    }else if(action == actProg){
		mdiArea->setActiveSubWindow(frmProg);
    }else if(action == actMeas){
		disconnect(thread, SIGNAL(measDataReady()), 0, 0);
		connect(thread, SIGNAL(measDataReady()), frmMeas, SLOT(showMeasData()));

		mdiArea->setActiveSubWindow(frmMeas);
    }else if(action == actMaster){
		if(frmCalb->getHueList() == false){
			// 没有有效的光量项目
			QMessageBox::warning(this, tr("CALIBRATION"), tr("NO VALID HUE,VL,DLM ITEM"));
		}else{
			disconnect(thread, SIGNAL(measDataReady()), 0, 0);
			connect(thread, SIGNAL(measDataReady()), frmCalb, SLOT(showMasterResult()));
			
			mdiArea->setActiveSubWindow(frmCalb);
		}
    }else if(action == actSetting){
		ConfigDlg* cDlg = new ConfigDlg(this);
		cDlg->exec();
		delete cDlg;
    }else{
    }

	qDebug() << "switch forms finished!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
*/
}

